<template>
  <el-dialog v-bind="$attrs" width="500px">
    <super-form
      label-width="150px"
      size="middle"
      form-ref="modalForm"
      :form-data="formData"
      :render-form-item="renderFormItem"
      :form-buttons="formButtons"
    />
  </el-dialog>
</template>

<script>
import SuperForm from '@/components/SuperForm'
import { updateFormItem } from './config'
import { fetchDepartDropdownList } from '../../../api/indicatorlib/department'

export default {
  name: 'AssessDepart',
  components: { SuperForm },
  props: {
    formData: {
      type: Object,
      default: () => ({})
    },
    handleSubmit: {
      type: Function,
      default: () => {}
    }
  },
  data() {
    return {
      renderFormItem: updateFormItem,
      formButtons: {
        isDialog: true,
        submitName: '提交',
        resetName: '取消',
        submitCallback: values => this.handleSubmit(values),
        resetCallback: () => this.$emit('update:visible', false)
      }
    }
  },
  mounted() {
    this.postDeptAllList()
  },
  methods: {
    postDeptAllList() {
      fetchDepartDropdownList({}).then(res => {
        this.$data.renderFormItem[0].slotAttrs.options = res.map(e => ({
          key: e.id,
          value: e.name
        }))
      })
    }
  }
}
</script>

<style lang="scss" scoped>
/deep/ .el-dialog__header{
  border-bottom: 1px solid #eaeaea;
}
</style>
